<?php

// +----------------------------------------------------------------------
// | H1CMS © OpenSource CMS
// +----------------------------------------------------------------------
// | Copyright (c) 2014-2016 http://www.h1cms.com All rights reserved.
// | Copyright (c) 2014-2016 嘉兴领格信息技术有限公司，并保留所有权利。
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Allen <allen@lg4.cn>
// +----------------------------------------------------------------------
if (defined('LG_AUTOLOAD')) {
    return;
}

require __DIR__ . '/../vendor/autoload.php';

//后端常用函数
require __DIR__ . '/system/includes/common.php';


define('LG_AUTOLOAD', true);

define('ADMIN_PATH', __DIR__);

//APP 根目录
define('APP_PATH', __DIR__);


define('BASEURL', dirname(base_url()));

//ADMIN
define('LG_ADMIN', true);

//设置Alias
LG::setAlias('@app', APP_PATH);

if (config('config.debug', false)) {
    error_reporting(E_ALL ^ E_NOTICE);
    \Lg\Cache\Cache::disk()->clear();
}

//检查配置文件
if (!file_exists(CONFIG_DIR . 'database.php')) {
    header('HTTP/1.1 503 Service Unavailable.', true, 503);
    echo 'The application environment is not set correctly.';
    exit(1); // EXIT_ERROR
}

\h1cms\H1::$app = new \h1cms\H1();

//设置时区
date_default_timezone_set(Lg\Config::get('config.timezone', 'PRC'));
//设置语言
Lg\I18n\Language::setLanguage(get_option('system.admin_language', 'zh_CN'));

if (!defined('LG_ADMIN_LOGIN')) {
    //登录检查
    if (!h1cms\system\Auth::isLogin(true)) {
        lg_user_login();
    }
    //权限检查
    if (!h1cms\system\Auth::check()) {
        redirect_to('/auth/access_denied.php');
    }

    //初始化
    lg_system_init();
}

//Module autoload
if (file_exists(APP_PATH . '/' . module_name() . '/includes/autoload.php')) {
    include APP_PATH . '/' . module_name() . '/includes/autoload.php';
}


LG::Action();
